package com.example.customview

import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.customview.silder.RecycleAdapter

fun RecyclerView.removeItemDecorations() {
    while (this.itemDecorationCount > 0) {
        this.removeItemDecorationAt(0)
    }
}
object Ext {
    @JvmStatic
    @BindingAdapter(value = ["cmListData", "cmLimit"], requireAll = false)
    fun setDatas(view: RecyclerView, data: List<Any>?, cmLimit: Int?) {
        val values = mutableListOf<Any>()
        if (data != null) {
            if (cmLimit != null && cmLimit < data.size) {
                values.addAll(data.subList(0, cmLimit))
            } else {
                values.addAll(data)
            }
        }
        val adapter = (view.adapter as? RecycleAdapter)
        adapter?.data?.clear()
        adapter?.data?.addAll(values)
        adapter?.notifyDataSetChanged()
    }
}